home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / Shaders / TexturingAndModeling:AProceduralApproach / DPShaders / DPBrickBump.sl < prev    next >
Encoding:
Text File  |  1995-03-22  |  1.5 KB  |  56 lines

  1. #include "proctext.h"
  2.  
  3. #define BRICKWIDTH      0.25
  4. #define BRICKHEIGHT     0.08
  5. #define MORTARTHICKNESS 0.01
  6.  
  7. #define BMWIDTH         (BRICKWIDTH+MORTARTHICKNESS)
  8. #define BMHEIGHT        (BRICKHEIGHT+MORTARTHICKNESS)
  9. #define MWF             (MORTARTHICKNESS*0.5/BMWIDTH)
  10. #define MHF             (MORTARTHICKNESS*0.5/BMHEIGHT)
  11.  
  12. surface
  13. DPBrickBump(
  14.     uniform float Ka = 1;
  15.     uniform float Kd = 1;
  16.     uniform color Cbrick = color (0.5, 0.15, 0.14);
  17.     uniform color Cmortar = color (0.5, 0.5, 0.5);
  18.      )
  19. {
  20.     color Ct;
  21.     point Nf;
  22.     float ss, tt, sbrick, tbrick, w, h;
  23.     float scoord = s;
  24.     float tcoord = t;
  25.     float sbump, tbump, stbump;
  26.  
  27.     Nf = normalize(faceforward(N, I));
  28.  
  29.     ss = scoord / BMWIDTH;
  30.     tt = tcoord / BMHEIGHT;
  31.  
  32.     if (mod(tt*0.5,1) > 0.5)
  33.         ss += 0.5;  /* shift alternate rows */
  34.     sbrick = floor(ss); /* which brick? */
  35.     tbrick = floor(tt); /* which brick? */
  36.     ss -= sbrick;
  37.     tt -= tbrick;
  38.     w = step(MWF,ss) - step(1-MWF,ss);
  39.     h = step(MHF,tt) - step(1-MHF,tt);
  40.  
  41.     Ct = mix(Cmortar, Cbrick, w*h);
  42.  
  43.     /* compute bump-mapping function for mortar grooves */
  44.     sbump = smoothstep(0,MWF,ss) - smoothstep(1-MWF,1,ss);
  45.     tbump = smoothstep(0,MHF,tt) - smoothstep(1-MHF,1,tt);
  46.     stbump = sbump * tbump;
  47.  
  48.     /* compute shading normal */
  49.     Nf = calculatenormal(P + normalize(N) * stbump);
  50.     Nf = normalize(faceforward(Nf, I));
  51.  
  52.     /* diffuse reflection model */
  53.     Oi = Os;
  54.     Ci = Os * Ct * (Ka * ambient() + Kd * diffuse(Nf));
  55. }
  56.